//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package gitcode_triger

import (
	"fmt"
	"testing"
)

const _NOTE_HOOK_DATA = `
{
  "object_kind": "note",
  "event_type": "note",
  "user": {
    "id": 571598,
    "name": "linksaas",
    "username": "linksaas",
    "avatar_url": "https://cdn-img.gitcode.com/ee/bc/4e4989e374bc76aa35d49d5217bd120e1b5d0e8ac0defb05f64d2b976b6276ed.png?time=1717491324683",
    "email": "panleiming@linksaas.pro"
  },
  "project_id": 4603033,
  "project": {
    "id": 4603033,
    "name": "flow_server",
    "description": "OpenLinkSaas的dev flow服务端实现",
    "web_url": "https://gitcode.com/devflow/flow_server",
    "avatar_url": "https://cdn-img.gitcode.com/ee/bc/4e4989e374bc76aa35d49d5217bd120e1b5d0e8ac0defb05f64d2b976b6276ed.png?time=1717491324683",
    "git_ssh_url": "git@gitcode.com:devflow/flow_server.git",
    "git_http_url": "https://gitcode.com/devflow/flow_server.git",
    "namespace": "devflow",
    "visibility_level": 20,
    "path_with_namespace": "devflow/flow_server",
    "default_branch": "main",
    "homepage": "https://gitcode.com/devflow/flow_server",
    "url": "git@gitcode.com:devflow/flow_server.git",
    "ssh_url": "git@gitcode.com:devflow/flow_server.git",
    "http_url": "https://gitcode.com/devflow/flow_server.git"
  },
  "object_attributes": {
    "author_id": 571598,
    "change_position": {},
    "created_at": "2025-01-22T18:56:33+08:00",
    "discussion_id": "495997b2b16bb035e475c1996fb0fb88aca7a9a4",
    "id": 77590164,
    "noteable_id": 2879520,
    "noteable_type": "Issue",
    "original_position": {},
    "position": {},
    "project_id": 4603033,
    "system": false,
    "type": "DiscussionNote",
    "updated_at": "2025-01-22T18:56:33+08:00",
    "url": "https://gitcode.com/devflow/flow_server/issues/1#note_495997b2b16bb035e475c1996fb0fb88aca7a9a4"
  },
  "repository": {
    "name": "flow_server",
    "url": "git@gitcode.com:devflow/flow_server.git",
    "description": "OpenLinkSaas的dev flow服务端实现",
    "homepage": "https://gitcode.com/devflow/flow_server",
    "git_http_url": "https://gitcode.com/devflow/flow_server.git",
    "git_ssh_url": "git@gitcode.com:devflow/flow_server.git",
    "visibility_level": 20
  },
  "issue": {
    "author_id": 571598,
    "author": {
      "avatar_url": "https://cdn-img.gitcode.com/ee/bc/4e4989e374bc76aa35d49d5217bd120e1b5d0e8ac0defb05f64d2b976b6276ed.png?time=1717491324683",
      "web_url": "https://gitcode.com/linksaas",
      "name": "linksaas",
      "id": 571598,
      "email": "panleiming@linksaas.pro",
      "username": "linksaas"
    },
    "confidential": false,
    "created_at": "2025-01-22T18:54:20+08:00",
    "id": 2879520,
    "iid": 1,
    "project_id": 4603033,
    "relative_position": 1073742323,
    "state": "opened",
    "title": "test",
    "updated_at": "2025-01-22T18:56:33+08:00",
    "url": "https://gitcode.com/devflow/flow_server/issues/1",
    "total_time_spent": 0,
    "assignee_ids": []
  },
  "produce_random_id": "074f49b4-8420-485d-8ab4-8699751d1cbf",
  "manual_build": false,
  "uuid": "4f9522a1-1e29-43d9-93a3-f4f3716b1aa2"
}
`

func TestExtractNoteHookAttr(t *testing.T) {
	attrList, err := ExtractNoteHookAttr([]byte(_NOTE_HOOK_DATA))
	if err != nil {
		t.Fatal(err)
		t.FailNow()
	}
	fmt.Println(attrList)
}
